package com.swpu.project.strategy.searchimpl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.swpu.project.model.entity.Secondary;
import com.swpu.project.strategy.FilterContext;
import com.swpu.project.strategy.SearchFilter;

import java.util.HashMap;
import java.util.Map;

public class FilterContextForSec implements FilterContext<Secondary> {


    Map<String, SearchFilter> foFilterMap;

public FilterContextForSec()
{
    foFilterMap = new HashMap<String, SearchFilter>();
    foFilterMap.put("blockName", new BlockFilterSec());
    foFilterMap.put("oilwellName", new OilwellFilterSec());
    foFilterMap.put("fluidName", new FluidFilterSec());
    foFilterMap.put("position", new PositionFilterSec());
    foFilterMap.put("lithology", new LithologyFilterSec());
    foFilterMap.put("name", new NameFilterSec());
}

    public LambdaQueryWrapper<Secondary> makeFilterCondtion(LambdaQueryWrapper<Secondary> lambdaQueryWrapper, Map<String,String> filterCondtions)
    {
        for (Map.Entry<String, String> entry : filterCondtions.entrySet()) {

            String key = entry.getKey();
            String value = entry.getValue();
            SearchFilter searchFilter = foFilterMap.get(key);
            if(searchFilter!=null&& StrUtil.isNotBlank(value))
                searchFilter.doFilter(lambdaQueryWrapper,value);



        }

        return lambdaQueryWrapper;

    }

    class NameFilterSec implements SearchFilter<Secondary>
    {


        @Override
        public void doFilter(LambdaQueryWrapper<Secondary> lambdaQueryWrapper,String value) {
            lambdaQueryWrapper.like(Secondary::getName,value);
        }


    }

    class BlockFilterSec implements SearchFilter<Secondary>
    {


        @Override
        public void doFilter(LambdaQueryWrapper<Secondary> lambdaQueryWrapper, String value) {
            lambdaQueryWrapper.like(Secondary::getBlockName,value);
        }


    }

    class OilwellFilterSec implements SearchFilter<Secondary>
    {


        @Override
        public void doFilter(LambdaQueryWrapper<Secondary> lambdaQueryWrapper,String value) {
            lambdaQueryWrapper.like(Secondary::getOilwellName,value);
        }


    }
    class PositionFilterSec implements SearchFilter<Secondary>
    {


        @Override
        public void doFilter(LambdaQueryWrapper<Secondary> lambdaQueryWrapper, String value) {
            lambdaQueryWrapper.like(Secondary::getPosition,value);
        }


    }
    class LithologyFilterSec implements SearchFilter<Secondary>
    {


        @Override
        public void doFilter(LambdaQueryWrapper<Secondary> lambdaQueryWrapper,String value) {
            lambdaQueryWrapper.like(Secondary::getLithology,value);
        }


    }   class FluidFilterSec implements SearchFilter<Secondary>
    {


        @Override
        public void doFilter(LambdaQueryWrapper<Secondary> lambdaQueryWrapper,String value) {
            lambdaQueryWrapper.like(Secondary::getFluidName,value);
        }


    }

}
